package com.ymatou.iapi.accounting.service;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ymatou.iapi.accounting.parameter.AccountBean;
import com.ymt.base.YmatouBaseCall;
import com.ymttest.utils.EnvSetup;
/**
*根据用户编号获取其所有的账户列表Call
*FreeMaker Template自动生成代码
*/
public class GetAccountListByUserIdCall extends YmatouBaseCall{
	private static String opurl ="api/Account/GetAccountListByUserId";
	
	public GetAccountListByUserIdCall() {
		super(EnvSetup.getSystemUrl("accounting_iapi"),opurl,"POST","JSON");
	}
	@Override
	public void addDefHeader() {
		client.addHeader("Accept","text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}
	
	//get statuscode
	public String getStatuscode(){
		String status=null;
		try {
			status = new JSONObject(getReturnData()).getString("StatusCode");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return status;
		
	}	
	
	//get msg
	public String getMsg(){
		String msg=null;
		try {
			msg = new JSONObject(getReturnData()).getString("Message");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return msg;
		
	}	
	
	
	//get accountList
	public String getAccountList(){
		String accountList=null;
		try {
			accountList = new JSONObject(getReturnData()).getJSONObject("Data").optString("AccountList");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return accountList;
		
	}			
	//get the return account info list
	public ArrayList<AccountBean> getReturnAccountList() throws JSONException{
		ArrayList<AccountBean> list = new ArrayList<AccountBean>();		
		String accountList = getAccountList();
		if (accountList!=null){			
			Gson gson = new Gson();
			list = gson.fromJson(accountList, new TypeToken<ArrayList<AccountBean>>() {
			}.getType());
		}
		return list;
	}	
}